package com.ekalenchuk.module.dao.user;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.ekalenchuk.module.dao.GenericHibernateDao;
import com.ekalenchuk.module.domain.user.User;
import com.ekalenchuk.module.exception.entity.NotFoundException;

@Repository
public class UserDaoImpl extends GenericHibernateDao<User, Long> implements UserDao {

	public User getUserByFacebookId(Long fbId) throws NotFoundException {
		User user = (User) getSession().createCriteria(User.class).add(Restrictions.eq("facebookId", fbId.toString())).uniqueResult();
		if (user == null) {
			throw new NotFoundException();
		}
		return user;
	}

	public User getUserByLogin(String login) throws NotFoundException {
		User user = (User) getSession().createCriteria(User.class).add(Restrictions.eq("login", login)).uniqueResult();
		if (user == null) {
			throw new NotFoundException();
		}
		return user;
	}

}
